package com.turnengine.client.global.user.command;

import com.turnengine.client.global.game.enums.GameLevel;
import com.turnengine.client.global.user.enums.UserPermissionType;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Set User Game Permission.
 */
public class SetUserGamePermission implements ISetUserGamePermission {

	/** The command id. */
	public static final short COMMAND_ID = 515;

	/** The login id. */
	private long loginId;
	/** The user id. */
	private int userId;
	/** The id. */
	private int id;
	/** The type. */
	private UserPermissionType type;
	/** The level. */
	private GameLevel level;

	/**
	 * Creates a new Set User Game Permission.
	 */
	public SetUserGamePermission() {
	}

	/**
	 * Creates a new Set User Game Permission.
	 * @param loginId the login id
	 * @param userId the user id
	 * @param id the id
	 * @param type the type
	 * @param level the level
	 */
	public SetUserGamePermission(long loginId, int userId, int id, UserPermissionType type, GameLevel level) {
		setLoginId(loginId);
		setUserId(userId);
		setId(id);
		setType(type);
		setLevel(level);
	}

	/**
	 * Creates a new Set User Game Permission.
	 * @param iSetUserGamePermission the i set user game permission
	 */
	public SetUserGamePermission(ISetUserGamePermission iSetUserGamePermission) {
		setLoginId(iSetUserGamePermission.getLoginId());
		setUserId(iSetUserGamePermission.getUserId());
		setId(iSetUserGamePermission.getId());
		setType(iSetUserGamePermission.getType());
		setLevel(iSetUserGamePermission.getLevel());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the user id.
	 * @return the user id.
	 */
	public int getUserId() {
		return userId;
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the type.
	 * @return the type.
	 */
	public UserPermissionType getType() {
		return type;
	}

	/**
	 * Returns the level.
	 * @return the level.
	 */
	public GameLevel getLevel() {
		return level;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the user id.
	 * @param userId the user id to set.
	 */
	public void setUserId(int userId) {
		this.userId = userId;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the type.
	 * @param type the type to set.
	 */
	public void setType(UserPermissionType type) {
		if (type == null) {
			throw new NullPointerException("type");
		}
		this.type = type;
	}

	/**
	 * Sets the level.
	 * @param level the level to set.
	 */
	public void setLevel(GameLevel level) {
		if (level == null) {
			throw new NullPointerException("level");
		}
		this.level = level;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(311, 37);
		hash.append(loginId);
		hash.append(userId);
		hash.append(id);
		hash.append(type);
		hash.append(level);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof SetUserGamePermission) {
			SetUserGamePermission compare = (SetUserGamePermission) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			equals.append(this.userId, compare.userId);
			equals.append(this.id, compare.id);
			equals.append(this.type, compare.type);
			equals.append(this.level, compare.level);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ISetUserGamePermission compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		builder.append(this.userId, compare.getUserId());
		builder.append(this.id, compare.getId());
		builder.append(this.type, compare.getType());
		builder.append(this.level, compare.getLevel());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		string.append("userId", userId);
		string.append("id", id);
		if (type != null) {
			string.append("type", type);
		}
		if (level != null) {
			string.append("level", level);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
